package com.example.aabb;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;


public class Page2Fragment extends Fragment {

    private RecyclerView recyclerView;
    private BillAdapter3 adapter;
    private List<Bill2> billList = new ArrayList<>();
    TextView tv_total,tt;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View vooview = inflater.inflate(R.layout.fragment_page2, container, false);
        initMonthlyBillViews(vooview);
        return vooview;
    }




    private void initMonthlyBillViews(View view) {

        recyclerView = view.findViewById(R.id.recyclerView);

        tt = view.findViewById(R.id.tt);
        // 设置布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        // 初始化数据（这里只是示例，你可以替换为真实数据）
        billList.add(new Bill2(R.mipmap.ic_launcher, "转账", 690.00,"一月"));
        billList.add(new Bill2(R.mipmap.ic_launcher, "消费支出", 600.00,"二月"));
        billList.add(new Bill2(R.mipmap.ic_launcher, "发红包", 200.00,"三"));
        billList.add(new Bill2(R.mipmap.ic_launcher, "亲属卡交易", 127.50,"四月"));
        // 创建适配器并设置给RecyclerView
        adapter = new BillAdapter3(billList);
        recyclerView.setAdapter(adapter);

        double taaa = 0.0;
        for (int i = 0; i < billList.size(); i++) {
            taaa = taaa+(billList.get(i).getAmount());
        }
        tt.setText("共支出"+billList.size()+"笔，合计"+taaa);

        // 以下是之前的按钮点击事件等相关代码（如果有），这里省略了具体实现
        Button expenseButton = view.findViewById(R.id.expense_button);
        Button incomeButton = view.findViewById(R.id.income_button);
        Button otherButton = view.findViewById(R.id.other_button);


        incomeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理收入按钮点击事件
            }
        });

        otherButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理其他按钮点击事件
            }
        });
    }
}